package com.gxa.controller.commserve;

import com.gxa.common.utils.Result;
import com.gxa.dto.commservedto.RepairSearchCriteria;
import com.gxa.service.commserve.RepairService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:18:00
 */
@Api(tags = "用户报修")
@RestController
@RequestMapping("/repair")
public class RepairController {
    @Autowired
    private RepairService repairService;

//    List<Repair> repairList;
//    Date date = new Date("2022/10/11");
//    public RepairController(){
//        this.init();
//    }
//    void init(){
//        repairList = new ArrayList<>();
//        Repair repair = new Repair(1,"BX238198244","综合楼101室","打印机设备故障",date,date,0,"李四","12345678999",0);
//        repairList.add(repair);
//        Repair repair1 = new Repair(2,"BX238198244","综合楼101室","打印机设备故障",date,date,0,"李四","12345678999",0);
//        repairList.add(repair1);
//    }


    @CrossOrigin(origins = "*",maxAge = 3600)//跨域请求配置
    @ApiOperation(value = "查询用户报修")
    @GetMapping("list/{pageNum}/{pageSize}")
    public Result list(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize){
       try {
           Map<String, Object> map = this.repairService.queryList(pageNum, pageSize);
           return Result.success(map);
       }catch (Exception e){
           e.printStackTrace();
           return Result.failed("查询失败");
       }
    }


    @CrossOrigin(origins = "*",maxAge = 3600)//跨域请求配置
    @ApiOperation(value = "搜索用户报修")
    @PostMapping("search")
    public Result search(@RequestBody RepairSearchCriteria repairSearchCriteria, Integer pageNum, Integer pageSize){
        try{
            Map<String, Object> map = this.repairService.queryListBySearch(repairSearchCriteria, pageNum, pageSize);
            return Result.success(map);
        }catch (Exception e){
            e.printStackTrace();
            return Result.failed("搜索失败");
        }
    }







}
